#include "namedPipe.hpp"

int main()
{
    // 1.以只写打开文件
    int wfd = open(fifo_name.c_str(), Write);
    if (wfd < 0)
    {
        std::cerr << "write open fail !!!errno:" << errno << strerror(errno) << std::endl;
    }
    // 2.写入数据
    char buff[buf] = {0};
    while (true)
    {
        std::cout << "client send messages:";
        fgets(buff, sizeof(buff) - 1, stdin); //fgets会将字符和你输入的回车一并存入buff,因此要-1避免写入\n
        buff[strlen(buff) - 1] = '\0'; //让最后一个字符为\0，从而去掉行末的\n
        if (strcmp("exit", buff) == 0)
            break;
        write(wfd, buff, sizeof(buff)); //-1
    }
    close(wfd);

    return 0;
}